//泛型接口: 在定义接口的时候 为接口的属性或方法定义泛型类型  在使用接口的时候 再致电具体的泛型类型
(()=>{
    class User{
        id?:number
        name:string
        age:number
        constructor(name:string,age:number) {
            this.name = name
            this.age = age
        }
    }
    interface IBaseCRUD<T> {
        data:Array<T>
        add:(t:T)=>T
        getUserId:(id:number) =>T
    }

    class UserCRUD implements IBaseCRUD<User>{
        data:Array<User>=[]
        add(user:User):User{
            user.id = Date.now()+Math.random()
            this.data.push(user)
            return user
        }
        getUserId(id:number):User{
            return this.data.find(user=>user.id === id)
        }
    }
    const userCRUD:UserCRUD = new UserCRUD()
    userCRUD.add(new User('jack',20))
    userCRUD.add(new User('rose',22))
    userCRUD.add(new User('lucy',21))
    userCRUD.add(new User('haoya',10))
    userCRUD.add(new User('jack',99))
    console.log(userCRUD.data);
    
})()